package org.cqust.backend.repository.mission;

import org.cqust.backend.entity.mission.MissionVersion;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;


public interface MissionVersionRepository extends JpaRepository<MissionVersion, Long> {
    //根据任务ID，获取任务目前最新版本的missionVersion
    @Query("SELECT mv FROM MissionVersion mv WHERE mv.mission.id = :missionId and mv.obsolete = false")
    Optional<MissionVersion> findCurrentMissionVersionByMissionId(@Param("missionId") Long missionId);

    //根据MissionVersionID将其设为过期
    @Query("UPDATE MissionVersion mv SET mv.obsolete = true WHERE mv.id = :missionVersionId")
    void updateAllByMissionVersionIdAndSetObsoleteTrue(@Param("missionVersionId") Long missionVersionId);
}
